package com.maishi.programmer.jainzhioffer;

/**
 * Created by brossdong on 2018/4/14.
 * 经过的结点（含根、叶结点）形成树的一条路径，最长路径的长度为树的深度。
 */
public class TestProblem55 {

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
        public TreeNode (int val) {
            this.val = val;
        }
    }

    public int TreeDepth(TreeNode root) {
        int deep = 0;
        if (root != null) {
            int lchilddeep = TreeDepth(root.left);
            int rchilddeep = TreeDepth(root.right);
            deep = lchilddeep > rchilddeep ? lchilddeep + 1 : rchilddeep + 1;
        }
        return deep;
    }

}
